/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aexbanner;

import fontys.observer.RemotePropertyListener;
import java.rmi.RemoteException;
import java.util.*;
/**
 *
 * @author Administrator
 */
public class MockEffectenbeurs implements IEffectenbeurs {

    private MockFonds[] fondsen;
    
    private Timer timer;
    
    public MockEffectenbeurs()
    {
        fondsen = new MockFonds[5];
        fondsen[0] = new MockFonds("Philips",100);
        fondsen[1] = new MockFonds("ASML",140);
        fondsen[2] = new MockFonds("Koekjes",60);
        fondsen[3] = new MockFonds("KPN",500.43);
        fondsen[4] = new MockFonds("Tom Tom",4607);
        timer = new Timer();
        timer.schedule(new MockTimerTask(this), 1000, 1000);
    }
    
    @Override
    public IFonds[] getKoersen() {
        return fondsen;
    }
    
    public void randomizeKoersen(){
        Random r = new Random();
        for(MockFonds fonds : fondsen){
            fonds.setKoers(fonds.getKoers()+(r.nextInt(2)-1)* r.nextDouble()*10);
        }
    }

    @Override
    public void addListener(RemotePropertyListener rl, String string) throws RemoteException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeListener(RemotePropertyListener rl, String string) throws RemoteException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    class MockTimerTask extends TimerTask
    {

        private MockEffectenbeurs beurs;
        
        public MockTimerTask(MockEffectenbeurs beurs){
            this.beurs = beurs;
        }
        
        @Override
        public void run() {
            beurs.randomizeKoersen();
        }
        
    }
    
}
